<!--
功能：管理员总组件,
作者：RanSheng,
邮箱：1534677527@qq.com",
时间：2021/5/31 20:32,
版本：v1.0,
修改记录：,
修改内容：,
修改人员：,
修改时间：,
-->
<template>
  <div class="app">
    <div class="root-header">
      <div class="header-bgc">
        <el-carousel height="160px" :interval="5000">
          <el-carousel-item v-for="item in bgc"
                            :key="item.id">
            <el-image :src="item.bgcUrl"
                      fit="fill"
                      class="image"></el-image>
          </el-carousel-item>
        </el-carousel>
      </div>
      <div class="header-logo">
        <div class="logo">
          <el-image :src="logoUrl"
                    class="image"
                    fit="fill"></el-image>
        </div>
      </div>
    </div>
    <div class="root-box">
      <div class="box-nave">
        <div class="nave"
             v-for="n in nave"
             :key="n.id"
             :class="op1==n.id? 'naveBgc':''"
             @click="handle(n)">
          <span><i :class="n.icon"></i></span>
          {{ n.name }}
        </div>
      </div>
      <div class="box-main">
        <!--        动态组件-->
        <transition mode="out-in" name="t">
          <keep-alive>
            <component name="keep" :is="com[op1-1]"></component>
          </keep-alive>
        </transition>
      </div>
    </div>
  </div>
</template>

<script>
import {setCookie} from "@/utils/CookieUtils";
import {message} from "@/utils/age";
//组件导入 只可以直接导入
import floor from './Floor'
import user from './User'
import apply from './Apply'
import examine from './Examine'
import notice from './Notice'
import {mapState} from "vuex";

export default {
  name: "Root",
  data() {
    return {
      nave: [{
        id: 1,
        name: '楼层管理',
        icon: 'el-icon-eleme',
        is: 'floor'
      }, {
        id: 2,
        name: '学员信息',
        icon: 'el-icon-eleme',
        is: 'user'
      }, {
        id: 3,
        name: '申请批准',
        icon: 'el-icon-eleme',
        is: 'apply'
      }, {
        id: 4,
        name: '考核处理',
        icon: 'el-icon-eleme',
        is: 'examine'
      }, {
        id: 5,
        name: '寝室公告',
        icon: 'el-icon-eleme',
        is: 'notice'
      }],
      bgc: [{
        id: 1,
        bgcUrl: require('../../assets/imag/welcome7.jpg')
      }, {
        id: 2,
        bgcUrl: require('../../assets/imag/welcome16.jpg')
      }, {
        id: 3,
        bgcUrl: require('../../assets/imag/welcome17.jpg')
      }, {
        id: 4,
        bgcUrl: require('../../assets/imag/welcome18.jpg')
      }, {
        id: 5,
        bgcUrl: require('../../assets/imag/welcome19.jpg')
      }, {
        id: 6,
        bgcUrl: require('../../assets/imag/welcome20.jpg')
      }],
      com:["floor","user","apply","examine","notice"],
      logoUrl: 'https://fuss10.elemecdn.com/0/6f/e35ff375812e6b0020b6b4e8f9583jpeg.jpeg',
    };
  },
  components: {
    floor,
    user,
    apply,
    examine,
    notice
  },
  computed: {
    ...mapState(["op1"])
  },
  mounted() {
    //选择

    // 房间 人数 数据请求
    this.$http.get('root/floor').then(response => {
      if (response.data) {
        this.$store.commit("setFloor", response.data)
        message("success", "查询成功")
      } else {
        message("error", "未知的错误")
      }
    }).catch(err => {
      message("error", "请求参数错误")
    })

    //  发送请求 判别身份
    this.$http.get('root/one').then(response => {
      message("success","成功")
    }).catch(err => {
      message("error", "请求参数错误")
    })
  },
  methods: {
    handle(n){
      this.currentView=n.is
      this.$store.commit("setOption",n.id)
    }
  },
  watch: {},
  destroyed() {

  },
}
</script>

<style scoped>
.app {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.image {
  width: 100%;
  height: 100%;
}

/*左边*/
.root-box {
  width: 100%;
  min-height: 700px;
  display: flex;
}

.box-nave {
  width: 10%;
  padding-top: 50px;
  box-sizing: border-box;
  /*background-color: #F3F3F3;*/
  border-right: 2px solid #F5F7FA;
}

.nave {
  width: 100%;
  height: 50px;
  margin-top: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  letter-spacing: 2px;
  cursor: pointer;
  transition: all .4s;
}
.naveBgc{
  color: #ffffff;
  background-color: #6E6E6E;
}
.nave span {
  margin-right: 5px;
}

/**/

/*主图*/
.box-main {
  width: 90%;
  box-sizing: border-box;
  padding: 20px 40px;
}


/**/
/*头部*/
.root-header {
  width: 100%;
  height: 160px;
  position: relative;
}

.header-bgc {
  position: absolute;
  top: 0;
  right: 0;
  width: 100%;
  height: 100%;
}

.header-logo {
  width: 10%;
  height: 100%;
  position: relative;
}

.logo {
  position: absolute;
  bottom: -40px;
  left: 50%;
  transform: translate(-50%, 0);
  width: 80px;
  height: 80px;
  border-radius: 50%;
  overflow: hidden;
  z-index: 10;
  box-shadow: 0 0px 3px 5px rgba(0, 0, 0, 0.2);
}


/**/
.t-enter,
.t-leave-to {
  opacity: 0;
}
.t-enter-active,
.t-leave-active {
  transition: all 0.4s;
}

</style>
